#!/usr/bin/perl -w
use warnings;
use strict;

my $indent_len = 4;

my @opts;
my @lens = (0, 0, 0);
my @lines = @ARGV ? <> : <DATA>;
for (@lines) {
    next unless /^\s*(\S+)\s+(\S+)\s+(.+)$/;
    next if /^\s*[\#]\s/;
    my @list = ($1, $2, $3);
    $list[0] = "'$list[0]'" unless $list[0] =~ /^\W.*\W$/;
    $list[1] = "'$list[1]'" unless $list[1] =~ /^\W.*\W$/;
    $list[2] = "'$list[2]'" unless $list[2] =~ /^\W.*\W$/ || $list[2] =~ /^\W*undef\W*$/;
    push @opts, [ @list ];
    map {;
        $lens[$_] = length $list[$_] if length $list[$_] > $lens[$_];
    } 0 .. 2;
}

map {;
   $lens[$_] += $indent_len - $lens[$_] % $indent_len;
} 0 .. 2;

my $indent = " " x $indent_len;
my ($n_name, $n_option, $n_value) = @lens;
print "# format-length: @lens\n";
print "my \%options = (\n";
for my $o (@opts) {
    printf "${indent}\%-${n_name}s => +{ option => \%-${n_option}s, value => \%${n_value}s, },\n",
        @$o;
}
print ");\n";

__DATA__
